/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package co.edu.senaclem.logica;

import co.edu.senaclem.modelo.Clienteexterno;
import co.edu.senaclem.persistencia.IClienteExternoDAO;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author anfeles
 */
@Stateless
public class ClienteExternoLogica implements ClienteExternoLogicaLocal {

    @EJB
    private IClienteExternoDAO clienteExternoDAO;
    
    @Override
    public void registrar(Clienteexterno clienteExterno) throws Exception {
        if(clienteExterno==null) {
            throw new Exception("El Cliente Externo es Nulo!");
        }
        
        if(clienteExterno.getDocumentocliente()==null || clienteExterno.getDocumentocliente()==0) {
            throw new Exception("La Identificación es Obligatoria!");
        }
        
        //consulta si el personal ya existe
        Clienteexterno entity=clienteExternoDAO.consultarPorId(clienteExterno.getDocumentocliente());
        if(entity!=null){
            throw new Exception("El Cliente Externo Ya Existe!"); 
        }
        
        clienteExternoDAO.insertar(clienteExterno);
    }

    @Override
    public Clienteexterno consultarPorId(Long documentocliente) throws Exception {
         if(documentocliente==null || documentocliente==0){
            throw new Exception("La Cédula es Obligatoria!");
        }
        
        return clienteExternoDAO.consultarPorId(documentocliente);
    }

    
}
